package cn.szzsi.model;

import cn.szzsi.model.base.BaseAction;
import com.alibaba.fastjson.support.odps.udf.CodecCheck;

import java.util.List;

/**
 * Created by zhengy on 2017/1/16.
 */
//@TableBind(tableName = "b_action_manage",pkName = "id")
public class Action extends BaseAction<Action> {
    public static Action dao=new Action().dao();

    public void init(){
        String resourceId = this.getStr("resourceId");
        Resource br = Resource.dao.findById(resourceId);
        this.put("resourceName",br == null?"":br.getStr("name"));
    }

    public Resource getByResourceId(){
        return Resource.dao.findById(getStr("resourceId"));
    }

    /**
     *
     * @param id 动作ID
     * @return
     */
    public boolean isExsitById(String id){
        Action a=Action.dao.findById(id);
        if(a!=null){
            return true;
        }else{
            return false;
        }
    }

    //资源和动作是否对应在一起
    public boolean isActionResourceRalationExsit(String actionId,String resourceId){
        List<Action> actions = Action.dao.find("select * from sys_action where id = ? and resourceId = ?",actionId,resourceId);
        if(actions!=null && actions.size()>0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * @param resourceId
     * @param shopId
     * @return
     */
    public List<Action> getByResourceIdAndShopId(String resourceId, String shopId){
        return Action.dao.find("select * from sys_action where resourceId = ? and shopId =?",resourceId,shopId);
    }

}
